package voidgame.core;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

public class DetailPanel extends JPanel{
	
	Game game;
	
	public DetailPanel(Game g){
		
		game=g;
		this.setBackground(Color.BLACK);
		this.setForeground(Color.GREEN);
		
	}
	
	public void paint(Graphics g) {
		
		super.paint(g);
		
		Graphics2D g2d = (Graphics2D) g;
       
		Font font = new Font("Lucida Console", Font.PLAIN, 14);
		g2d.setFont(font);

		g2d.drawString("DETAIL PANEL", 20, 20);
		g2d.drawString(game.player.starSystem.name+" System", 20, 40);
       	
		if(game.gameMode==Game.GAMEMODEINSPECT){
			NavigatePanel nav = (NavigatePanel)game.mainPanel.getComponent(0);
			Cell cell = game.player.starSystem.map[nav.centerPoint[0]+nav.inspectPos[0]][nav.centerPoint[1]+nav.inspectPos[1]];
			drawCellDetails(g2d, cell);
		}
		
		if(game.gameMode==Game.GAMEMODENAVIGATE){
			Cell cell = game.player.starSystem.map[game.player.pos[0]][game.player.pos[1]];
			drawCellDetails(g2d, cell);
		}
		
		
		
		

	}
	
	public void drawCellDetails(Graphics2D g2d, Cell cell){
		String inspectDetail="";
		switch(cell.type){
			case 0:{
				inspectDetail="Empty Space";
				break;
			}
			case 1:{
				Star star = (Star)cell.obj;
				inspectDetail="Star: "+star.name+": "+star.desc;
				break;
			}
			case 2:{
				Planet planet = (Planet)cell.obj;
				inspectDetail="Planet: "+planet.name+": "+planet.desc;
				break;
			}
			case 3:{
				Moon moon = (Moon)cell.obj;
				inspectDetail="Moon: "+moon.name+": "+moon.desc;
				break;
			}
			case 4:{
				Wormhole hole = (Wormhole)cell.obj;
				inspectDetail=hole.alpha.name+"-"+hole.beta.name+" Wormhole";
				break;
			}
		}
		
		int descStartPos=0;
		int lineCount=0;
		while(descStartPos<inspectDetail.length()){
			int descEndPos=descStartPos+25;
			if(descEndPos>=inspectDetail.length())
				descEndPos=inspectDetail.length();
			
			if(!inspectDetail.substring(descEndPos, descEndPos).equals(" ")&&descEndPos!=inspectDetail.length()&&inspectDetail.substring(descStartPos, descEndPos).lastIndexOf(" ")>0&&descStartPos!=inspectDetail.substring(descStartPos, descEndPos).lastIndexOf(" ")){
			
				//System.out.println("SPACE CHECK: "+(!inspectDetail.substring(descEndPos, descEndPos).equals(" "))+" "+(descEndPos!=inspectDetail.length())+" "+(inspectDetail.substring(descStartPos, descEndPos).lastIndexOf(" ")>0)+" "+(descStartPos!=inspectDetail.substring(descStartPos, descEndPos).lastIndexOf(" ")));
				descEndPos=inspectDetail.substring(descStartPos, descEndPos).lastIndexOf(" ")+descStartPos+1;
			
			}
			//System.out.println("DETAIL PRINT: "+descStartPos+" "+descEndPos+" "+inspectDetail.length());
			
			g2d.drawString(inspectDetail.substring(descStartPos, descEndPos), 20, 60+(lineCount*15));
			descStartPos=descEndPos;
			lineCount++;
		}
	}
	
}